/*
 * @Description  :
 * @Version      : 0.1
 * @Company      : V-Think Development Team
 * @Author       : KiraVerSace@yeah.net
 * @Date         : 2025-01-09 16:24:00
 */
#ifndef __X_META_DATA_DEFINE_H__
#define __X_META_DATA_DEFINE_H__

#include <Arduino.h>

#define  TERMINAL_CLEAR     "\033[2J\033[1H"

typedef enum    // 波特率枚举定义 [BAUD_RATE_9600]
{
    BAUD_RATE_4800   = 0,
    BAUD_RATE_9600   = 1,
    BAUD_RATE_19200  = 2,
    BAUD_RATE_38400  = 4,
    BAUD_RATE_57600  = 5,
    BAUD_RATE_115200 = 6
} BaudRate;


typedef enum    // 奇偶校验枚举定义 [PARITY_NONE]
{
    PARITY_NONE = 0,
    PARITY_ODD  = 1,
    PARITY_EVEN = 2
} Parity;


typedef enum    // 停止位枚举定义 [STOP_BITS_1]
{
    STOP_BITS_1 = 0,
    STOP_BITS_2 = 1
} StopBits;

typedef struct
{
    uint16_t modbusAddress;
    uint16_t baudRate;
    uint16_t parity;
    uint16_t stopBit;

    uint16_t defaultCH1Output;   // CH1默认输出值
    uint16_t defaultCH2Output;   // CH2默认输出值
    uint16_t defaultRelayOutput; // Relay默认输出值

    uint16_t dacCalibrationA0;
    uint16_t dacCalibrationA1;
    uint16_t dacCalibrationA2;
    uint16_t dacCalibrationA3;
    uint16_t dacCalibrationA4;
    uint16_t dacCalibrationA5;
    uint16_t dacCalibrationA6;
    uint16_t dacCalibrationA7;
    uint16_t dacCalibrationA8;
    uint16_t dacCalibrationA9;
    uint16_t dacCalibrationA10;

    uint16_t dacCalibrationB0;
    uint16_t dacCalibrationB1;
    uint16_t dacCalibrationB2;
    uint16_t dacCalibrationB3;
    uint16_t dacCalibrationB4;
    uint16_t dacCalibrationB5;
    uint16_t dacCalibrationB6;
    uint16_t dacCalibrationB7;
    uint16_t dacCalibrationB8;
    uint16_t dacCalibrationB9;
    uint16_t dacCalibrationB10;
}__attribute__((packed)) XStoreParameterT;
extern XStoreParameterT xParameter;

typedef struct
{
    uint16_t mvCH1;
    uint16_t mvCH2;

    uint16_t relayOutput;
}XSensorDataT;
extern XSensorDataT xSensorData;

typedef enum
{
    MB_ADDRESS            = 0,
    MB_BAUD_RATE          = 1,
    MB_PARITY             = 2,
    MB_STOP_BIT           = 3,
    MB_DA_DEFAULT_CH1     = 4,
    MB_DA_DEFAULT_CH2     = 5,
    MB_DA_DEFAULT_RELAY   = 6,

    MB_DA_CALIBRATION_A0  = 10,
    MB_DA_CALIBRATION_A1  = 11,
    MB_DA_CALIBRATION_A2  = 12,
    MB_DA_CALIBRATION_A3  = 13,
    MB_DA_CALIBRATION_A4  = 14,
    MB_DA_CALIBRATION_A5  = 15,
    MB_DA_CALIBRATION_A6  = 16,
    MB_DA_CALIBRATION_A7  = 17,
    MB_DA_CALIBRATION_A8  = 18,
    MB_DA_CALIBRATION_A9  = 19,
    MB_DA_CALIBRATION_A10 = 20,

    MB_DA_CALIBRATION_B0  = 21,
    MB_DA_CALIBRATION_B1  = 22,
    MB_DA_CALIBRATION_B2  = 23,
    MB_DA_CALIBRATION_B3  = 24,
    MB_DA_CALIBRATION_B4  = 25,
    MB_DA_CALIBRATION_B5  = 26,
    MB_DA_CALIBRATION_B6  = 27,
    MB_DA_CALIBRATION_B7  = 28,
    MB_DA_CALIBRATION_B8  = 29,
    MB_DA_CALIBRATION_B9  = 30,
    MB_DA_CALIBRATION_B10 = 31,

    MB_MV_CH1             = 100,
    MB_MV_CH2             = 101,
    MB_RELAY_OUTPUT       = 102
} ModbusMap;

/*
 * DAC校准数据表 - 基于实测数据
 * 格式: {设定值mV, CH1输出值mV, CH2输出值mV}
 */
#define DAC_CALIBRATION_TABLE_SIZE 11

typedef struct
{
    uint16_t inputMV;
    uint16_t outputCH1;
    uint16_t outputCH2;
} datadacCalibrationTableT;

#endif
